/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Queryform.java
 *
 * Created on Oct 14, 2011, 1:37:12 PM
 */

package diva_lm;

/**
 *
 * @author KMD_Computer Centre
 */
import java.io.FileNotFoundException;
import javax.swing.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
public class Queryform extends javax.swing.JFrame {

    /**
     * QueryForm constructor
     */
    public Queryform() {
        try
        {
            //create controls
            initComponents();
            
            //read data from MusicData.txt file
            readDataFromMusicDataTextFile();    
        }
        catch(Exception ex)
        {
            JOptionPane.showMessageDialog(null, ex.getMessage().toString(),"Eror",JOptionPane.ERROR_MESSAGE);
        }
    }

    /**
     * Read data from MusicData.txt file and store it in CommonClass ArrayList
     * @throws IOException
     * @throws FileNotFoundException 
     */
    private void readDataFromMusicDataTextFile() throws IOException, FileNotFoundException {
        //initialize member variable
        this.CommonClass = new ArrayList<CommonClass>();
        
        //get MusicData.txt file
        BufferedReader mybuffer = new BufferedReader(new FileReader("MusicData.txt"));
        
        //read line by line from the MusicData.txt file
        String row;
        while( (row = mybuffer.readLine())!= null)
        {
            String [] musicdata = row.split(",");
            CommonClass myCommonClass= new CommonClass();
            myCommonClass.DrawerName= musicdata[0];
            myCommonClass.DrawerNo=musicdata[1];
            myCommonClass.SongTitle=musicdata[2];
            myCommonClass.Publisher=musicdata[3];
            myCommonClass.ConcertType=musicdata[4];
            myCommonClass.Author=musicdata[5];
            myCommonClass.LengthOfSong=musicdata[6];
            
            //add each row in the MusicData.txt to array list
            this.CommonClass.add(myCommonClass);
        }
        
        //close reader
        mybuffer.close();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable3 = new javax.swing.JTable();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTable4 = new javax.swing.JTable();
        jbtnSearch = new javax.swing.JButton();
        jbtnCancle = new javax.swing.JButton();
        jbtnExit = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jtfSongTitle = new javax.swing.JTextField();
        jScrollPane5 = new javax.swing.JScrollPane();
        jtbMusicData = new javax.swing.JTable();
        jbtnShowAll = new javax.swing.JButton();
        jbtnReport = new javax.swing.JButton();
        jtfDrawerName = new javax.swing.JTextField();
        jtfConcertType = new javax.swing.JTextField();
        jtfAuthor = new javax.swing.JTextField();
        jtfPublisher = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jchkdrawername = new javax.swing.JCheckBox();
        jchkconcerttype = new javax.swing.JCheckBox();
        jchksongtitle = new javax.swing.JCheckBox();
        jchkauthor = new javax.swing.JCheckBox();
        jchkpublisher = new javax.swing.JCheckBox();

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(jTable2);

        jTable3.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane3.setViewportView(jTable3);

        jTable4.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane4.setViewportView(jTable4);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Search Form");
        setBackground(new java.awt.Color(255, 255, 255));

        jbtnSearch.setText("Search");
        jbtnSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnSearchActionPerformed(evt);
            }
        });

        jbtnCancle.setText("Cancle");
        jbtnCancle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnCancleActionPerformed(evt);
            }
        });

        jbtnExit.setText("Exit");
        jbtnExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnExitActionPerformed(evt);
            }
        });

        jLabel1.setText("Drawer Name");

        jtfSongTitle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfSongTitleActionPerformed(evt);
            }
        });

        jtbMusicData.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "null", "null", "null", "null", "null", "null", "null"
            }
        ));
        jScrollPane5.setViewportView(jtbMusicData);

        jbtnShowAll.setText("Show All");
        jbtnShowAll.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnShowAllActionPerformed(evt);
            }
        });

        jbtnReport.setText("Report");
        jbtnReport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnReportActionPerformed(evt);
            }
        });

        jtfAuthor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfAuthorActionPerformed(evt);
            }
        });

        jtfPublisher.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfPublisherActionPerformed(evt);
            }
        });

        jLabel2.setText("Concert Type");

        jLabel3.setText("Song Title");

        jLabel4.setText("Author");

        jLabel5.setText("Publisher");

        jchkdrawername.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jchkdrawernameActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jbtnSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(20, 20, 20)
                        .addComponent(jbtnShowAll, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jbtnReport, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jbtnCancle, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jbtnExit, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(80, 80, 80)
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE)
                                .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE)
                                .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addGap(175, 175, 175)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jtfPublisher, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jchkpublisher))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jtfAuthor, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jchkauthor))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jtfSongTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jchksongtitle))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jtfConcertType, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jchkconcerttype))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jtfDrawerName, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(32, 32, 32)
                                .addComponent(jchkdrawername)))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtfDrawerName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jchkdrawername)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jtfConcertType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jtfSongTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jtfAuthor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jchkauthor))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jtfPublisher, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jchkpublisher)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel5))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jchkconcerttype)
                        .addGap(18, 18, 18)
                        .addComponent(jchksongtitle)))
                .addGap(64, 64, 64)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jbtnSearch)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jbtnExit)
                        .addComponent(jbtnCancle)
                        .addComponent(jbtnReport))
                    .addComponent(jbtnShowAll))
                .addGap(7, 7, 7)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 336, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-640)/2, (screenSize.height-471)/2, 640, 471);
    }// </editor-fold>//GEN-END:initComponents

    private void jbtnExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnExitActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jbtnExitActionPerformed

    /**
     * This event will fire when Cancel button is clicked in the form(UI).
     * @param evt :event variable
     */
    private void jbtnCancleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnCancleActionPerformed
        //empty all the textboxes
        jtfDrawerName.setText("");
        jtfAuthor.setText("");
        jtfConcertType.setText("");
        jtfSongTitle.setText("");
        jtfPublisher.setText("");
            
        //unchecked all the checkboxes
        jchkauthor.setSelected(false);
        jchkconcerttype.setSelected(false);
        jchkdrawername.setSelected(false);
        jchkpublisher.setSelected(false);
        jchksongtitle.setSelected(false);
    }//GEN-LAST:event_jbtnCancleActionPerformed

    private void jtfSongTitleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfSongTitleActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtfSongTitleActionPerformed

    private void jtfAuthorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfAuthorActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtfAuthorActionPerformed

    private void jtfPublisherActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfPublisherActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtfPublisherActionPerformed
    private boolean isSearchCriteriaEnteredCorrectly() {
        int errorCount =0;
        
        //validate drawer name
        String drawername;
        drawername = jtfDrawerName.getText();
        if (jchkdrawername.isSelected()==true)
        {
            if (drawername.equals(""))
            {
                errorCount++;
                JOptionPane.showMessageDialog(this,"Please Enter the Drawer Name","Message",JOptionPane.ERROR_MESSAGE);
            }
        }
        
        //valide concert type
        String concerttype;
        concerttype = jtfConcertType.getText();
        if (jchkconcerttype.isSelected()==true)
        {
            if (concerttype.equals(""))
            {
                errorCount++;
                JOptionPane.showMessageDialog(this,"Please Enter the Concert Type","Message",JOptionPane.ERROR_MESSAGE);
            }
        }
        
        //validate song title
        String songtitle;
        songtitle = jtfSongTitle.getText();
        if (jchksongtitle.isSelected()==true)
        {
            if (songtitle.equals(""))
            {
                errorCount++;
                JOptionPane.showMessageDialog(this,"Please Enter the Song Title","Message",JOptionPane.ERROR_MESSAGE);
            }
        }
        
        //validate author
        String author;
        author = jtfAuthor.getText();
        if (jchkauthor.isSelected()==true)
        {
            if (author.equals(""))
            {
                errorCount++;
                JOptionPane.showMessageDialog(this,"Please Enter the Author","Message",JOptionPane.ERROR_MESSAGE);
            }
        }
        
        //validate publisher
        String publisher;
        publisher = jtfPublisher.getText();
        if (jchkpublisher.isSelected()==true)
        {
            if (publisher.equals(""))
            {
                errorCount++;
                JOptionPane.showMessageDialog(this,"Please Enter the Publisher","Message",JOptionPane.ERROR_MESSAGE);
            }
        }
        
        //is there any error?
        if(errorCount>0){
            return false;//yes,there is error
        }else{
            return true;//no,there is no error
        }
    }
    private void jbtnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnSearchActionPerformed

        if(!isSearchCriteriaEnteredCorrectly()){
            //if the validation failed, don't do any searching.
            return;
        }
        
        //this code will execute, if the validation is successful
        //get input data
        String drawername = jtfDrawerName.getText();
        String concerttype = jtfConcertType.getText();
        String songtitle = jtfSongTitle.getText();
        String author = jtfAuthor.getText();
        String publisher = jtfPublisher.getText();
        
        this.CommonClassresult = new java.util.ArrayList<CommonClass>();
        
        for (int i=0;i<this.CommonClass.size();i++)
        {
            CommonClass objCommonClass = new CommonClass();
            objCommonClass = this.CommonClass.get(i);
            if (jchkdrawername.isSelected()==true)
            {
                if(objCommonClass.DrawerName.equals(drawername)==true)
                {
                    this.CommonClassresult.add(objCommonClass);
                    continue;
                }
            }
            if (jchkconcerttype.isSelected()==true)
            {
                if(objCommonClass.ConcertType.equals(concerttype)==true)
                {
                    this.CommonClassresult.add(objCommonClass);
                    continue;
                }
            }
            if (jchksongtitle.isSelected()==true)
            {
                if(objCommonClass.SongTitle.equals(songtitle)==true)
                {
                    this.CommonClassresult.add(objCommonClass);
                    continue;
                }
            }
            if (jchksongtitle.isSelected()==true)
            {
                if(objCommonClass.SongTitle.equals(songtitle)==true)
                {
                    this.CommonClassresult.add(objCommonClass);
                    continue;
                }
            }
            if (jchkpublisher.isSelected()==true)
            {
                if(objCommonClass.Publisher.equals(publisher)==true)
                {
                    this.CommonClassresult.add(objCommonClass);
                    continue;
                }
            }
        }

        this.createMusicDataTableColum();
        for (int i=0;i<this.CommonClassresult.size();i++)
        {
            Object [] musicdatarow ={
                                        this.CommonClassresult.get(i).DrawerName,
                                        this.CommonClassresult.get(i).DrawerNo,
                                        this.CommonClassresult.get(i).SongTitle,
                                        this.CommonClassresult.get(i).Publisher,
                                        this.CommonClassresult.get(i).ConcertType,
                                        this.CommonClassresult.get(i).Author,
                                        this.CommonClassresult.get(i).LengthOfSong
                                    };
            this.MusicData.addRow(musicdatarow);
        }
        jtbMusicData.setModel(this.MusicData);
    }//GEN-LAST:event_jbtnSearchActionPerformed

    private void jbtnShowAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnShowAllActionPerformed
        try
        {
            this.createMusicDataTableColum();
            this.CommonClassresult=new ArrayList<CommonClass>();
            BufferedReader myreader = new BufferedReader(new FileReader("MusicData.txt"));
            String readerhead;
            while((readerhead= myreader.readLine())!=null)
            {
                String [] musicdata= readerhead.split(",");
               CommonClass detailCommonClassdata=new CommonClass();
               detailCommonClassdata.DrawerName=musicdata[0];
               detailCommonClassdata.DrawerNo=musicdata[1];
               detailCommonClassdata.SongTitle=musicdata[2];
               detailCommonClassdata.Publisher=musicdata[3];
               detailCommonClassdata.ConcertType=musicdata[4];
               detailCommonClassdata.Author=musicdata[5];
               detailCommonClassdata.LengthOfSong=musicdata[6];
               CommonClassresult.add(detailCommonClassdata);
               this.createMuscDataTableRow(readerhead);

            }
            myreader.close();
            jtbMusicData.setModel(this.MusicData);
        }
        catch(IOException ioe)
        {
            JOptionPane.showMessageDialog(null, ioe.getMessage().toString(),"Eror",JOptionPane.ERROR_MESSAGE);
        }

    }//GEN-LAST:event_jbtnShowAllActionPerformed

    private void jchkdrawernameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jchkdrawernameActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jchkdrawernameActionPerformed

    private void jbtnReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnReportActionPerformed

        try
        {
             BufferedWriter mybufferwriter = new BufferedWriter(new FileWriter("ReportMusicData.txt"));
             for (int i=0;i<this.CommonClassresult.size();i++)
             {
                CommonClass myCommonClass = new CommonClass();
                myCommonClass=this.CommonClassresult.get(i);
                String line = myCommonClass.DrawerName+"\t"+
                        myCommonClass.DrawerNo+"\t"+
                        myCommonClass.SongTitle+"\t"+
                        myCommonClass.Publisher+"\t"+
                        myCommonClass.ConcertType+"\t"+
                        myCommonClass.Author+"\t"+
                        myCommonClass.LengthOfSong;
                        mybufferwriter.write(line);
                        mybufferwriter.newLine();
             }
             mybufferwriter.flush();;
             mybufferwriter.close();
             JOptionPane.showMessageDialog(this,"Report (ReportMusicData.txt) is successfully exported.","Message",JOptionPane.ERROR_MESSAGE);
             //String [] command = new Arraylist[];
             //command = ("cmd","\C","start","ReportMusicData.txt");
             //Runtime.getRuntime().exec(command);
        }
        catch(Exception ex)
        {
            JOptionPane.showMessageDialog(null, ex.getMessage().toString(),"Eror",JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jbtnReportActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Queryform().setVisible(true);
               
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTable jTable3;
    private javax.swing.JTable jTable4;
    private javax.swing.JButton jbtnCancle;
    private javax.swing.JButton jbtnExit;
    private javax.swing.JButton jbtnReport;
    private javax.swing.JButton jbtnSearch;
    private javax.swing.JButton jbtnShowAll;
    private javax.swing.JCheckBox jchkauthor;
    private javax.swing.JCheckBox jchkconcerttype;
    private javax.swing.JCheckBox jchkdrawername;
    private javax.swing.JCheckBox jchkpublisher;
    private javax.swing.JCheckBox jchksongtitle;
    private javax.swing.JTable jtbMusicData;
    private javax.swing.JTextField jtfAuthor;
    private javax.swing.JTextField jtfConcertType;
    private javax.swing.JTextField jtfDrawerName;
    private javax.swing.JTextField jtfPublisher;
    private javax.swing.JTextField jtfSongTitle;
    // End of variables declaration//GEN-END:variables
    private javax.swing.table.DefaultTableModel MusicData;
    private java.util.ArrayList<CommonClass> CommonClass;
    private java.util.ArrayList<CommonClass> CommonClassresult = new java.util.ArrayList<CommonClass> ();
   
    
    private void createMusicDataTableColum()
    {
        this.MusicData = new  javax.swing.table.DefaultTableModel();
        this.MusicData.addColumn("Drawer Name");
        this.MusicData.addColumn("Drawer No");
        this.MusicData.addColumn("Song Title");
        this.MusicData.addColumn("Publisher");
        this.MusicData.addColumn("Concert Type");
        this.MusicData.addColumn("Author");
        this.MusicData.addColumn("Length Of Song");
    }

    private void createMuscDataTableRow(String Row)
    {
        String[] myRow=Row.split(",");
        Object[] Data={
        myRow[0],myRow[1],myRow[2],myRow[3],myRow[4],myRow[5],myRow[6]};

        this.MusicData.addRow(myRow);


    }
}
